#!D:\Python312
import time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
# 搜索发送微信消息

# 打开任意一个安装程序
# app = Application(backend="uia").connect(process=2600)
app = Application(backend="uia").connect(title="微信")
print(app)

dlg = app["微信"]

while True:
    liaotian = dlg.child_window(title="搜索", control_type="Edit")
    liaotian.click_input()
    dlg.type_keys('%V {BACKSPACE 20}', with_spaces=True)
    dlg.type_keys('廖志得', with_spaces=True)
    time.sleep(1)
    send_keys('{ENTER}')
    msg = "周末去哪玩"

    send_keys(msg)
    time.sleep(1)
    send_keys('{ENTER}')